|
|
|
|
|
|
|
Incorrect number of parameters |
|
|
|
|
|
|
|
|
Incorrect size of a function return value |
|
|
|
|
|
|
|
|
Incorrect size of parameters |
|
|
|
|
|
|
|
|
Functions in the stdcall calling convention are almost always returned using CPU registers and thus have no impact on the stack. The exceptions to this are data types that cannot fit into a register (such as variants and user-defined structures). In order to return these data types, the calling function first allocates space on the stack within its own stack frame for the return value (just as it would allocate space for any other local variable). It then passes a pointer to that space as an extra parameter to the DLL function. The DLL function loads the space with the return value, then returns the pointer value that was passed to it as an extra parameter. You can find more information on how values are returned from DLL functions in Solution 29, ''What Do You Do When It Mega Hurts?" (in Part II of this book). |
|
|
|
|
|
|
|
|
The stack under 32-bit operating systems is always 32 bits wide. Those parameters that use data types larger than 32 bits actually use more than one entry in the stack. Table 4.1 shows the size of parameters as they are passed on the stack. |
|
|
|
|
| PARAMETER DATA TYPE | SIZE ON THE STACK |  |
|
|
|
|
Numeric types passed ByVal
(Byte, Integer, Long) |
|
|
|
| 32 bits |  |
|
|
|
|
All data types when passed
By Reference (ByRef) |
|
|
|
| 32 bits | | User-defined types | 32 bits (pointer to space on calling stack) | | Double | 64 bits (2 stack entries) | | Currency | 64 bits (2 stack entries) | | Variants | 128 bits (4 stack entries) | | Table T4-1: Size of parameters as they are passed on the stack |
|
|
|
|
|
|
Further information on passing parameters by value and by reference can be found in Tutorial 5, "The ByVal Keyword: The Solution to 90 Percent of All API Problems." |
|
|
|
|
|